//********************************************************************
//      PP5_7.java              Author:GK
//
//      “石头-剪刀-布”游戏程序。
//********************************************************************
import java.util.*;

public class PP5_7 {
    public static void main(String[] args) {
        //------------------------------------------------------------
        //  实例化game的ArrayList<String>对象
        //------------------------------------------------------------
        int a;
        int draw = 0, win = 0, lost = 0;
        String b, another = "y";
        ArrayList<String> game = new ArrayList<>();

        game.add("石头");
        game.add("剪刀");
        game.add("布");

        Random generator = new Random();
        while (another.equalsIgnoreCase("y")) {
            a = generator.nextInt(3);
            b = game.get(a);

            String str;
            Scanner scan = new Scanner(System.in);
            System.out.print("请输入“石头-剪刀-布”：");
            str = scan.nextLine();

            System.out.println("计算机： " + b);
            System.out.println("您：" + str);

            if (b.equals(str))
            {System.out.println("平局");
            draw++;}
            else
                if (str.equals("剪刀") || str.equals("布") || str.equals("石头")){
                    if ((b.equals("石头") && str.equals("剪刀")) || (b.equals("布") && str.equals("石头")) ||
                            (b.equals("剪刀") && str.equals("布"))) {
                        System.out.println("Sorry, You lost.");
                        lost++;
                    } else {
                        System.out.println("Great! You win! ");
                        win++;
                    }
                }
                else
                    System.out.println("Be serious!");
            System.out.println();
            System.out.print("Again(y/n)?");
            another = scan.nextLine();
        }
        System.out.println();
        System.out.println("win: " + win);
        System.out.println("lost: " + lost);
        System.out.println("draw: " + draw);
    }
}
